package com.toppitch.site.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.toppitch.site.data.Student;
import com.toppitch.site.data.User;

@Controller
@RequestMapping("/")
public class StudentController extends UserBaseController {

	@RequestMapping("studentHome")
	public String home(
			//
			@RequestParam(value = "page", defaultValue = "1") String page,//
			@RequestParam(value = "count", defaultValue = "10") String count,//
			@RequestParam(value = "searchWords", defaultValue = "") String searchWords,//
			HttpSession session, ModelMap model) {
		setupNYTNews(model);
		Object st = session.getAttribute("STUDENT");
		if (st != null && st instanceof Student) {
			model.addAttribute("user", st);

			home(page, count, searchWords, model, true, ((User) st).getEmail());

			return "student/home";
		}
		return "login";
	}

	@RequestMapping("studentMyPitches")
	public String myPitches(//
			@RequestParam(value = "page", defaultValue = "1") String page,//
			HttpSession session, ModelMap modelMap) {
		setupNYTNews(modelMap);
		Object st = session.getAttribute("STUDENT");
		if (st != null && st instanceof Student) {
			modelMap.addAttribute("user", st);
			mine(page, ((User) st).getEmail(),modelMap);
			return "student/myPitches";
		}
		return "login";
	}

	@RequestMapping("studentNewPitch")
	public String newPitch(HttpSession session, ModelMap modelMap) {
		setupNYTNews(modelMap);
		Object st = session.getAttribute("STUDENT");
		if (st != null && st instanceof Student) {
			modelMap.addAttribute("user", st);
			return "student/newPitch";
		}
		return "login";
	}

}
